
class TreeNode{
    public String val;
    public TreeNode left;
    public TreeNode right;

    public TreeNode(String val) {
        this.val = val;
    }
}



public class BinaryTree {

    //前期：采用穷举方式创建二叉树
    public TreeNode CreateBinaryTree(){
        TreeNode A = new TreeNode("A");
        TreeNode B = new TreeNode("B");
        TreeNode C = new TreeNode("C");
        TreeNode D = new TreeNode("D");
        TreeNode E = new TreeNode("E");

        A.left = B;
        B.left = D;
        A.right = C;
        C.left = E;
        return A;

    }


    public void PreOrderBinaryTree(TreeNode root){
        if(root==null){
            return;
        }
        System.out.print(root.val+" ");
        PreOrderBinaryTree(root.left);
        PreOrderBinaryTree(root.right);
    }


    public void inOrderBinaryTree(TreeNode root){
        if(root==null){
            return;
        }
        inOrderBinaryTree(root.left);
        System.out.print(root.val+" ");
        inOrderBinaryTree(root.right);
    }


    public void PostOrderBinaryTree(TreeNode root){
        if(root==null){
            return;
        }
        PostOrderBinaryTree(root.left);
        PostOrderBinaryTree(root.right);
        System.out.print(root.val+" ");
    }


    //遍历思路：求结点个数
    public static int size = 0;
    public int getSize(TreeNode root){
        if(root==null){
            return 0;
        }

        getSize(root.left);
        getSize(root.right);
        BinaryTree.size++;
        return BinaryTree.size;
    }

    //子问题思路：求结点个数
    public int getSize2(TreeNode root){
        if(root==null){
            return 0;
        }
        return getSize2(root.left)+getSize2(root.right)+1;
    }
}
